Skip to main content

Overview

The ui package implements the Bubble Tea model for Duet’s terminal user interface, managing screens, room interactions, terminal display, and AI sidebar.

Types

Model

Main UI model managing all application state.

Screen

Enumeration of UI screens:
  • ScreenLaunch: Main menu
  • ScreenCreate: Create room form
  • ScreenJoin: Join room form
  • ScreenRoomCreated: Room created confirmation
  • ScreenRoom: Active room with terminal

InputMode

Terminal input modes:
  • ModeNormal: Direct terminal input
  • ModeAI: AI prompt input (Ctrl+G)
  • ModeSandbox: Sandbox command input (Ctrl+R)

Functions

New

Creates a new UI model instance.
*lipgloss.Renderer
required
Lipgloss renderer for styled output
*room.Manager
required
Room manager instance
string
required
SSH username (defaults to “guest” if empty)
Returns: Initialized *Model ready for Bubble Tea Example:

Init

Bubble Tea initialization command.
Returns: Tick command for toast expiration

Update

Bubble Tea update function handling messages.
Key Messages:
  • tea.WindowSizeMsg: Resize terminal and viewports
  • tea.KeyMsg: Keyboard input routing
  • terminalUpdateMsg: Terminal content changed
  • roomEventMsg: Room events (join/leave/typing/ai_sync)
  • AIResponseMsg: AI response received
  • SandboxResultMsg: Sandbox command completed

View

Bubble Tea view function rendering the UI.
Returns: Rendered screen as string

Message Types

GotoScreenMsg

Navigate to a different screen.

RoomCreatedMsg

Room successfully created.

RoomJoinedMsg

Successfully joined a room.

AIResponseMsg

AI response received.

SandboxResultMsg

Sandbox command output.

ToastMsg

Display a toast notification.

ErrorMsg

Error occurred.

Key Bindings

Launch Screen

  • c / C: Create room
  • J: Join room
  • / k: Move selection up
  • / j: Move selection down
  • Enter: Confirm selection
  • q / Esc: Quit

Room Screen (Normal Mode)

  • Ctrl+G: Open AI prompt
  • Ctrl+R: Open sandbox command
  • Ctrl+A: Toggle AI sidebar
  • Ctrl+J: Scroll AI sidebar down
  • Ctrl+K: Scroll AI sidebar up
  • Ctrl+L: Leave room
  • All other keys: Sent to terminal

AI/Sandbox Input Mode

  • Enter: Submit prompt/command
  • Esc: Cancel and return to normal mode

Layout Configuration

Sidebar visibility and layout adapt to terminal size.

Internal Methods

roomLayout

Calculates layout dimensions.
Returns:
  • sidebarW: User list width (1/6 of screen)
  • terminalW: Terminal width (remaining space)
  • aiSidebarW: AI sidebar width (1/4 if visible, 0 otherwise)
  • mainH: Main content height

startTerminal

Initializes or connects to room terminal.
Behavior:
  • Reuses existing room terminal if available
  • Creates new terminal with room workspace directory
  • Subscribes to terminal updates
  • Stores terminal reference in room for other clients

sendAIMessage

Sends AI prompt to worker.
string
required
User prompt
Returns: Command that yields AIResponseMsg or ErrorMsg

execSandboxCmd

Executes command in isolated sandbox.
string
required
Shell command to execute
Returns: Command that yields SandboxResultMsg or ErrorMsg

syncAIViewportContent

Rebuild AI viewport from room’s message history.
Use Cases:
  • Late joiners syncing chat history
  • Refreshing after another client sends AI message
  • Responding to “ai_sync” room events

addToast

Displays a temporary notification.
string
required
Toast message (visible for 1 second)
Limit: Maximum 3 toasts displayed at once

cleanup

Cleans up resources when leaving room.
Cleanup:
  • Unsubscribes from terminal updates
  • Leaves room via manager
  • Clears terminal reference
  • Resets room state

Example Usage